/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    bool hasCycle(ListNode *head) 
    {
        if(head == NULL || head -> next == NULL) 
            return false;
        
        ListNode* p = head;
        
        // FIXME: hashmap 最后初始化一下，初始成0；或者把下面的代码改一下，如下面的改动
        map <ListNode*, int> hashmap;
        
        while(p)
        {
            if(hashmap.count(p))
                return true;
            else
                hashmap[p] = 0;
            
            hashmap[p]++;
            p = p -> next;
        }
        
        return false;
    }
};